<template>
    <div class="photoinfo-container">
        <h3>{{photoinfo.title}}</h3>

        <div class="subtitle">
            <span>发表时间：{{photoinfo.addTime | dataFormat('YYYY-MM-DD') }}</span>
            <span>点击：{{photoinfo.click}}次</span>
        </div>

        <hr>

        <!-- <img class="preview-img" v-for="(item, index) in list" :src="item.src" height="100" @click="$preview.open(index, list)" :key="index"> -->
        <div class="thumbs">
            <vue-preview v-if='list' :slides="list" :thumbImageStyle="{width: '80px', height: '80px', margin: '10px'}" 
                :previewBoxStyle="{border: '1px solid #eee'}" @close="handleClose" class="preview"></vue-preview>
        </div>
        

        <div class="content" v-html="photoinfo.content"></div>

        <comment-box :id="this.id"></comment-box>
    </div>
</template>

<script>
import { Toast } from "mint-ui"
//导入子组件
import comment from '../subcomponents/comment.vue'
export default {
    data(){
        return {
            id:this.$route.params.id,
            photoinfo:{},
            list:[]
        }
    },
    methods:{
        getPhotoInfo(){
            this.$http.get("/src/data/imgShare/photoInfo.json").then(result => {
                if(result.body.status === 0){
                    this.photoinfo = result.body.message[0];
                }else {
                    Toast("获取图片信息失败！");
                }
            })
        },
        getPreviewimg(){
            this.$http.get("/src/data/imgShare/imgList.json").then(result => {
                 if(result.status === 200){
                    this.list = result.body["1"].map(function(item,index){
                        return {src:item,msrc:item,alt:'picture'+index,title:'imageCaption'+index,w:600,h:800}
                    });
                }else {
                    Toast("获取图片预览失败！");
                }
            })
        },
        handleClose () {
            console.log('close event')
        }
    },
    created(){
        this.getPreviewimg(),
        this.getPhotoInfo()
    },
    components:{
        'comment-box':comment
    }

}
</script>

<style lang="scss">
    .photoinfo-container{
        padding:3px;
        h3{
            color: #26A2FF;
            font-size: 20px;
            font-weight: 800;
            line-height: 30px;
        }
        .subtitle{
            font-size: 14px;
            line-height: 15px;
            color: rgb(153, 149, 149);
            display: flex;
            justify-content: space-between;
        }
        .content{ 
            p{
                text-indent:25px;
                color: rgb(112, 109, 109);
            }
            img{
                width:100%;
            }
        }
        .thumbs{
            figure{
                display: inline-block;
                // float: left;
                width: 20%;
                height:calc(30vw - 30px);
                margin: 2%;
            }
            
            img{
                // margin:10px;
                width:80px;
                height:80px;
                box-shadow: 0 0 8px #999;
            }
        }
    }
</style>